package com.scsj.supermarket.view.activity.settingmodel;

import android.os.Bundle;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.View;
import android.widget.TextView;

import com.scsj.supermarket.R;
import com.scsj.supermarket.utils.ClearEditText;
import com.scsj.supermarket.view.activity.baseactivitymodel.BaseActivity;
import com.zcw.togglebutton.ToggleButton;

/**
 * 找回密码，设置新密码
 */
public class SetNewPasswordActivity extends BaseActivity implements View.OnClickListener {

    private TextView next_step_tv,service_tv;
    private ClearEditText history_name_et,new_password_et;
    private ToggleButton adress_edit_toggle_btn;

    @Override
    protected void createView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_set_new_password);
        initToolbar();
        setToolbarTitle("找回密码");
        hasBack(true);
    }

    @Override
    protected void initView() {
        next_step_tv=findViewById(R.id.next_step_tv);
        history_name_et=findViewById(R.id.history_name_et);
        new_password_et=findViewById(R.id.new_password_et);
        service_tv=findViewById(R.id.service_tv);
        adress_edit_toggle_btn=findViewById(R.id.adress_edit_toggle_btn);
    }

    @Override
    protected void initListener() {
        next_step_tv.setOnClickListener(this);
        service_tv.setOnClickListener(this);
        adress_edit_toggle_btn.setOnToggleChanged(new ToggleButton.OnToggleChanged() {
            public void onToggle(boolean on) {
                if(on){
                    //开启
                    new_password_et.setInputType(InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                }else{
                    //关闭
                    new_password_et.setInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            }
        });
        history_name_et.addTextChangedListener(mEditText);
        new_password_et.addTextChangedListener(mEditText);
    }

    @Override
    protected void initData() {

    }

    TextWatcher mEditText = new TextWatcher() {
        private CharSequence temp;

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            temp = s;
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count,
                                      int after) {
//            adb_password.setVisibility(View.VISIBLE);
//            adb_lin2.setVisibility(View.GONE);
        }

        @Override
        public void afterTextChanged(Editable s) {
            if(history_name_et.getText().length()!=0&&new_password_et.getText().length()!=0){
//                ToastMiddleUtils.ToastMiddle(SetNewPasswordActivity.this,"");
                next_step_tv.setBackgroundResource(R.color.unify_red);
            }else{
                next_step_tv.setBackgroundResource(R.color.grayback);
            }

        }
    };

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.next_step_tv://确定

                break;
            case R.id.service_tv://联系客服

                break;
        }
    }
}
